/*
* @Author: xiaolai
* @Date:   2018-03-16 18:24:47
* @Last Modified by:   94468
* @Last Modified time: 2018-11-10 15:28:58
*/
// 文件上传
layui.define(['jquery'], function(exports){
    $ = layui.jquery;
    form = layui.form;
    var MOD_NANE = 'uploadfile';
    var index;
    var callback;

    // 树的公共事件
    var event = {
        getElemId: function (options) {	// 根据传入的参数获取ID
            var elem = options.elem || "";
            var obj = options.obj || $(elem);

            if (obj.length == 0) {	//页面中未找到绑定id
                return "";
            } else {
                return $(obj)[0].id;
            }
        },
        open: function(){
            return layer.open({
                type: 2,
                area: ['600px', '500px'],
                fix: true, //不固定
                shadeClose: true,
                shade:0.4,
                title: '文件上传',
                closeBtn:0,
                content: 'uploadFile.html',
                btnAlign: 'c',
            });
        }
    }

    var _event = {
        callback: function (data) {
            layer.close(index);
            callback(data);
        }
    }
    window.uploadfile = _event;

    /** 外部访问 **/
    var obj = {
        render: function (options) {	// 初始化
            var id = options.id;
            if(id == "") {
                layer.msg("页面中未找到绑定按钮id", {icon:5});
            } else {
                $(document).on('click',id,function(){
                   index = event.open();
                });
                callback=options.callback;
            }
        }
    }
    exports('uploadfile', obj);
});
